package com.ruoyi.system.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.Room;
import com.ruoyi.system.mapper.RoomMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.OldManMapper;
import com.ruoyi.system.domain.OldMan;
import com.ruoyi.system.service.IOldManService;
import com.ruoyi.common.core.text.Convert;

/**
 * 老人信息Service业务层处理
 * 
 * @author 王帅
 * @date 2024-08-24
 */
@Service
public class OldManServiceImpl extends ServiceImpl<OldManMapper,OldMan> implements IOldManService

{
    @Autowired
    private OldManMapper oldManMapper;
    @Autowired
    private RoomMapper roomMapper;

    /**
     * 查询老人信息
     * 
     * @param id 老人信息主键
     * @return 老人信息
     */
    @Override
    public OldMan selectOldManById(Long id)
    {
        return oldManMapper.selectOldManById(id);
    }

    /**
     * 查询老人信息列表
     * 
     * @param oldMan 老人信息
     * @return 老人信息
     */
    @Override
    public List<OldMan> selectOldManList(OldMan oldMan)
    {
        return oldManMapper.selectOldManList(oldMan);
    }

    /**
     * 新增老人信息
     * 
     * @param oldMan 老人信息
     * @return 结果
     */
    @Override
    public int insertOldMan(OldMan oldMan)
    {
        oldMan.setCreateTime(DateUtils.getNowDate());
        oldMan.setUpdateTime(DateUtils.getNowDate());
        Room room = roomMapper.selectRoomById(oldMan.getRoomId());
        oldMan.setRoomNumber(room.getRoomNumber());
        return oldManMapper.insertOldMan(oldMan);
    }

    /**
     * 修改老人信息
     * 
     * @param oldMan 老人信息
     * @return 结果
     */
    @Override
    public int updateOldMan(OldMan oldMan)
    {
        oldMan.setUpdateTime(DateUtils.getNowDate());
        return oldManMapper.updateOldMan(oldMan);
    }

    /**
     * 批量删除老人信息
     * 
     * @param ids 需要删除的老人信息主键
     * @return 结果
     */
    @Override
    public int deleteOldManByIds(String ids)
    {
        return oldManMapper.deleteOldManByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除老人信息信息
     * 
     * @param id 老人信息主键
     * @return 结果
     */
    @Override
    public int deleteOldManById(Long id)
    {
        return oldManMapper.deleteOldManById(id);
    }
}
